<?php
 /**
   * This file contains the function to return a fieldspec string for the fieldspec array describint the crudset  
   * @package phpnewmaker
   */
   
include_once "../../pdo_boot.php";




function makesuredir($dir){
	if(!file_exists(dirname($dir))){
		makesuredir(dirname($dir));
	}
	if(!file_exists($dir)){
		mkdir($dir);
	}
}

function fill_fs_from_cc($crudset_id){

$qry_delete = "DELETE FROM fieldspecs WHERE crudset_id = " . $crudset_id;

do_query($qry_delete);

$qry_fill = "INSERT INTO fieldspecs (col_order, crudset_id, variable_id, `show`, edit, `key`, `filter`,
 sort, `add`, size, rows, headname, date_show_format,
  date_source_format, source, makefunction, edit_as)
SELECT col_order, crudset_id, crudcols.variable_id, shown_in_list AS `show`,
 edit_in_list AS edit, crudcols.is_key AS `key`, 
filter, 1 AS sort, is_add AS `add`, size, `rows`, header_name AS headname,
'yyyy-mm-dd' AS date_show_format,'yyyy-mm-dd' AS date_source_format,
 table_alias AS source, makefunction ,
CASE edit_type
WHEN 'text' THEN 'ctl_text'
WHEN 'checkbox' THEN 'ctl_checkbox'
WHEN 'textarea' THEN 'ctl_textarea'
WHEN 'calendar' THEN 'ctl_jqdate'
WHEN 'calicon' THEN 'ctl_jqdate'
WHEN 'querylist' THEN 'ctl_select'
WHEN 'commalist' THEN 'ctl_select'
ELSE 'ctl_text' END AS edit_as
 FROM crudcols JOIN variables ON variables.variable_id = crudcols.variable_id
JOIN tablesources AS ts ON ts.tablesource_id = variables.source_id WHERE crudset_id = " . $crudset_id;

do_query($qry_fill);

}// end function

?>
